package com.claude.update;

import com.claude.bean.Version;
import com.claude.mainactivity.MyApplication;
import com.claude.util.Configure;


public class UpdateApp {
	private MyApplication mMyApplication = null;
	private Configure configure = null;
	public final static int UPDATE = 0;
	public final static int CHOSE_UPDATE = 1;
	public final static int NO_UPDATE = 2;

	public UpdateApp(MyApplication myApplication, double version) {
		mMyApplication = myApplication;
		configure = Configure.getInstance();
	}
	/**
	 * 
	 * @return 0 update, 1 chose to update, 2 no update
	 */
	public int neadUpdate() {
		String version = configure.getVersion();
		Version curVersion = mMyApplication.getVersion();
		if(curVersion == null){
			//No Connection
			return NO_UPDATE;
		}
		if(Double.parseDouble(version) < Double.parseDouble(curVersion.getVersion())){
			if(curVersion.getImportance().equals("true")){
				return UPDATE;
			}
			return CHOSE_UPDATE;
		}else{
			return NO_UPDATE;
		}
	}
}
